<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<jsp:include page="template-head.jsp" />
<jsp:include page="template-body.jsp"/>
<div id="surveysummarypage">
<div class="container">
<div class="hero-unit">
	<jsp:include page="errors.jsp"/>
	<div id="surveysummarypagebody">
	<c:choose>
		<c:when test="${not empty completesurvey}">
			<h2>Survey Completed</h2>
			<p>Thank you very much for taking the survey.</p>
		</c:when>
		<c:otherwise>
			<h2>List of questions for survey titled ${survey.title}</h2>
			<c:if test="${user.type == 2 && survey.sent == 1}">
				<h3>You have already sent this survey, so you can only view the questions of this survey.</h3>
			</c:if>
			
			<form id="surveysummaryform" method="post" action="surveysummary.do">
				<div>
				<table>
					<c:forEach var="question" items="${questionlist}">
						<tr>
							<td>${question.qnum}. ${question.question}</td>
							<td><a href="viewsurvey.do?value=${question.qid}&button=View">View this Question</a></td>
							<c:if test="${user.type == 2 && survey.sent == 0}">
								<td><a href="surveysummary.do?value=${question.qid}&button=Remove">Remove this Question</a></td>
								<td><a href="surveysummary.do?value=${question.qid}&button=Modify">Modify this Question</a></td>
								<td><a href="surveysummary.do?value=${question.qid}&button=Up">Shift Up</a></td>
								<td><a href="surveysummary.do?value=${question.qid}&button=Down">Shift Down</a></td>
							</c:if>
							<c:if test="${user.type == 3 && completedlist[question.qnum - 1] == true}">
								<td><i class="icon-ok"></i></td>
							</c:if>
		 				</tr>
					</c:forEach>
				</table>
				<c:if test="${user.type == 2}">
					<c:choose>
						<c:when test="${empty survey.mailinglist}">
							<h3>This survey has no associated mailing list. <a href="surveysummary.do?button=MailingList">Associate a mailing list now?</a></h3><br/><br/>
						</c:when>
						<c:otherwise>
							<h3>This survey is associated with mailing list named <a href="surveysummary.do?button=MailingListContent">${survey.mailinglist}</a>. 
							<c:if test="${survey.sent == 0}">
								<a href="surveysummary.do?button=MailingList">Associate a different mailing list?</a>
							</c:if></h3><br/><br/>
						</c:otherwise>
					</c:choose>
					<c:choose>
						<c:when test="${fn:length(entityclass) <= 1}">
							<h3>This survey has no imported entity classes. <a href="surveysummary.do?button=ImportEntity">Import an entity class?</a></h3>
						</c:when>
						<c:otherwise>
							<h3>This survey has imported following entity classes.</h3>
							<c:forEach var="ec" items="${entityclass}">
								<c:if test="${ec.name != 'Respondents'}">
									<h3><a href="surveysummary.do?value=${ec.name}&button=ImportEntityContent">${ec.name}</a></h3>
								</c:if>
							</c:forEach>
							<br/>
							<c:if test="${survey.sent == 0}">
								<h3>Would you like to <a href="surveysummary.do?button=ImportEntity">import more?</a></h3>
							</c:if>
						</c:otherwise>
					</c:choose>
					
					<input type="submit" name="button" class="btn btn-inverse" value="Go Back to List of Surveys">
					<input type="submit" name="button" class="btn btn-success" value="Create More Questions">
				</c:if>
				<c:if test="${user.type == 3}">
					<input type="submit" name="button" class="btn btn-success" value="Submit the Answers">
				</c:if>
				</div>
			</form>
		</c:otherwise>
	</c:choose>
	</div>
</div>
</div>
</div>
<jsp:include page="template-foot.jsp" /> 